/*
 *  Created at 2011-12-06 21:23 GMT-03:00
 *  Author: Victor Williams Stafusa da Silva
 *  JSmartUnit
 */
package org.jsmartunit.invocations;

import java.lang.reflect.Constructor;

import org.jsmartunit.model.ClassStructure;
import org.jsmartunit.model.TestRunner;
import org.jsmartunit.util.CollectionUtils;

import org.junit.runner.notification.RunNotifier;
import org.junit.runners.model.InitializationError;

/**
 * @author Victor Williams Stafusa da Silva
 */
public class ConstructorInvocation<U> implements Invocation {

    private final Constructor<U> constructor;
    private final Object[] args;

    public ConstructorInvocation(Constructor<U> constructor, Object[] args) {
        if (constructor == null) throw new IllegalArgumentException();
        if (args == null) throw new IllegalArgumentException();

        Class<?>[] formalParams = constructor.getParameterTypes();
        CollectionUtils.assertMatches(formalParams, args);

        this.constructor = constructor;
        this.args = args;
    }

    public U invokeExplosively() throws Throwable {
        return ClassStructure.invokeExplosively(constructor, args);
    }

    public TestRunner createRunner(TestRunner parentRunner, String name, RunNotifier notifier) throws InitializationError {
        throw new UnsupportedOperationException();
    }
}
